<?php

class UserIdentity extends CUserIdentity {
	public $fullname;

	public function __construct($username, $password) {
		$this->username    = $username;
		$this->password = $password;
	}

	public function authenticate() {
		$models = User::model()->findByAttributes(array('username' => $this->username));
		if(count($models) == 0) {
			$this->errorCode = self::ERROR_UNKNOWN_IDENTITY;
		} else if($models->password == "" || $models->password != $this->password) {
			$this->errorCode = self::ERROR_PASSWORD_INVALID;
		} else if($models->status == 0) {
			$this->errorCode = -1;
		} else {
			$this->errorCode = self::ERROR_NONE;
			$this->setState("id", $models->user_id);
			$this->setState("username", $this->username);
			$this->setState("fullname", $this->fullname);
		}
		return $this->errorCode;
	}
}